package com.zidongxiangxi.sharding.job.core.executor;

import com.zidongxiangxi.sharding.job.core.node.ShardingNode;
import lombok.Getter;

import java.util.Collections;

/**
 * 待执行的分片项
 *
 * @author chenxudong
 * @date 2021/03/03
 */
public class WaitingExecuteShardingItem {
    @Getter
    private final String shardingItem;
    private final ShardingNode shardingNode;

    public WaitingExecuteShardingItem(final String shardingItem, final ShardingNode shardingNode) {
        this.shardingItem = shardingItem;
        this.shardingNode = shardingNode;
    }

    public void start() {
        shardingNode.setShardingItemRunning(shardingItem);
    }

    public void stop() {
        shardingNode.clearShardingItemRunning(Collections.singletonList(shardingItem));
    }
}
